package com.lee.thread;

public class MyThreadPrinter3 implements Runnable {
	
	private String name;
	
	private Object prev;
	
	private Object self;

	public MyThreadPrinter3(String name, Object prev, Object self) {
		super();
		this.name = name;
		this.prev = prev;
		this.self = self;
	}

	@Override
	public void run() {
		int count = 10;
		while (count>0) {
			synchronized (prev) {
				synchronized (self) {
					self.notify();
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.print(name);
					count--;
				}
				try {
					prev.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
	public static void main(String[] args) throws InterruptedException {
		Object a = new Object();
		Object b = new Object();
		Object c = new Object();
		
		MyThreadPrinter3 ta = new MyThreadPrinter3("A", c, a);
		MyThreadPrinter3 tb = new MyThreadPrinter3("B", a, b);
		MyThreadPrinter3 tc = new MyThreadPrinter3("C", b, c);
		
		new Thread(ta).start();
		Thread.sleep(100);
		new Thread(tb).start();
		Thread.sleep(100);
		new Thread(tc).start();
		Thread.sleep(100);
	}
	
	
	
}
